/**
 * 
 */
package com.swim.natatoriuminfo.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.swim.natatoriuminfo.entity.NatatoriumInfo1;
import com.swim.natatoriuminfo.dao.NatatoriumInfoDao1;
import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.file.utils.FileUploadUtils;

/**
 * 游泳馆信息Service
 * @author ljw
 * @version 2022-06-06
 */
@Service
@Transactional(readOnly=true)
public class NatatoriumInfoService1 extends CrudService<NatatoriumInfoDao1, NatatoriumInfo1> {
	
	@Value("${server.context-path}")
	private String contextPath;
	
	/**
	 * 获取单条数据
	 * @param natatoriumInfo
	 * @return
	 */
	@Override
	public NatatoriumInfo1 get(NatatoriumInfo1 natatoriumInfo) {
		NatatoriumInfo1 result = super.get(natatoriumInfo);
		if (result != null) {
			//获取游泳馆图片
			List<FileUpload> fileUploadList = FileUploadUtils.findFileUpload(result.getId(), "natatoriumInfo_image");
			if (!CollectionUtils.isEmpty(fileUploadList)) {
				List<String> natatoriumInfoImageUrlList = new ArrayList<String>();	//游泳馆图片url集合
				for (FileUpload fileUploadListOne : fileUploadList) {
					natatoriumInfoImageUrlList.add(contextPath + "/userfiles/fileupload/" + fileUploadListOne.getFileEntity().getFilePath() + fileUploadListOne.getFileEntity().getFileId() + "." + fileUploadListOne.getFileEntity().getFileExtension());
					result.setNatatoriumInfoImageUrlList(natatoriumInfoImageUrlList);
				}
			}
		}
		return result;
	}
	
	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param natatoriumInfo
	 * @return
	 */
	@Override
	public Page<NatatoriumInfo1> findPage(Page<NatatoriumInfo1> page, NatatoriumInfo1 natatoriumInfo) {
		page.setPageSize(3);
		page.setPageNo(1);
		Page<NatatoriumInfo1> pageList = super.findPage(page, natatoriumInfo);
		List<NatatoriumInfo1> natatoriumInfoList = pageList.getList();
		if (!CollectionUtils.isEmpty(natatoriumInfoList)) {
			for (NatatoriumInfo1 natatoriumInfoOne : natatoriumInfoList) {
				//获取游泳馆图片
				List<FileUpload> fileUploadListOne = FileUploadUtils.findFileUpload(natatoriumInfoOne.getId(), "natatoriumInfo_image");
				if (!CollectionUtils.isEmpty(fileUploadListOne)) {
					List<String> natatoriumInfoImageUrlList = new ArrayList<String>();	//游泳馆图片url集合
					natatoriumInfoImageUrlList.add(contextPath + "/userfiles/fileupload/" + fileUploadListOne.get(0).getFileEntity().getFilePath() + fileUploadListOne.get(0).getFileEntity().getFileId() + "." + fileUploadListOne.get(0).getFileEntity().getFileExtension());
					natatoriumInfoOne.setNatatoriumInfoImageUrlList(natatoriumInfoImageUrlList);
				}
			}
		}
		pageList.setList(natatoriumInfoList);
		return pageList;
	}
	
}